import { DynamicModule, Module } from '@nestjs/common';
import { PrismaService } from './prisma.service';
import { PrismaModuleOptions, PrismaModuleAsyncOptions } from './prisma-options.interface';
import { PrismaCoreModule } from './prisma-core.module';

@Module({
  providers: [PrismaService],
  exports: [PrismaService]
})
export class PrismaModule {
  static forRoot(options: PrismaModuleOptions): DynamicModule
  static forRoot(url: string): DynamicModule


  static forRoot(arg: any) {
    let _options: PrismaModuleOptions;
    if(typeof arg === 'string') {
      _options = {
        url: arg
      }
    } else {
      _options = arg
    }

    return {
      module: PrismaModule,
      imports: [PrismaCoreModule.forRoot(_options)],
    }
  }

  static forRootAsync(options: PrismaModuleAsyncOptions): DynamicModule {
    return {
      module: PrismaModule,
      imports: [PrismaCoreModule.forRootAsync(options)],
    }
  }
}
